package com.supplychain.scm.core.common.exception;

import lombok.Getter;

/**
 * @author liyang
 * @version 1.0.0
 * @ClassName AbstractCustomException
 * @Description 抽象自定义异常
 * @createTime 16:11:00 2022/12/03
 */
public class CustomException extends RuntimeException{

    /**
     * 错误编码
     */
    @Getter
    protected Integer code;
    /**
     * 异常信息说明
     */
    @Getter
    protected String message;
    /**
     * 需要返回的异常信息
     */
    @Getter
    protected Object data;


    public CustomException(String errorMsg) {
        super(errorMsg);
        this.message = errorMsg;
    }

    public CustomException(String errorMsg,Object data) {
        super(errorMsg);
        this.message = errorMsg;
        this.data = data;
    }

    public CustomException(Integer code,String errorMsg) {
        super(errorMsg);
        this.message = errorMsg;
        this.code = code;
    }

    public CustomException(Integer code, String errorMsg, Throwable errorCourse) {
        super(errorMsg, errorCourse);
        this.code = code;
        this.message = errorMsg;
    }

    public CustomException(Integer code,String errorMsg, Object data) {
        super(errorMsg);
        this.code = code;
        this.message = errorMsg;
        this.data = data;
    }

    public CustomException(Integer code,String errorMsg, Object data, Throwable errorCourse) {
        super(errorMsg,errorCourse);
        this.code = code;
        this.message = errorMsg;
        this.data = data;
    }

    public static void fail(String message) {
        throw new CustomException(message, 500);
    }

    public static void fail(int code, String message) {
        throw new CustomException(code,message);
    }

    public static void fail(int code, String message,Object data) {
        throw new CustomException(code,message, data);
    }
}
